<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>观察者模式</title>
</head>
<body>
    <script>
        //发布者
        function Dep(){
            this.subs = [];
        }
        Dep.prototype = {
            addSub:(sub)=>{
                this.subs.push(sub)
            },
            notify:()=>{
                this.subs.forEach(sub => {
                    sub.update();
                });
            }
        }

        function Watcher(){

        }
        Watcher.prototype = {
            update:()=>{
                //notify to do something
            }
        }
    </script>
</body>
</html>